home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / s0ftpj / pippa_v2.txt < prev    next >
Encoding:
Text File  |  2000-12-17  |  15.2 KB  |  425 lines

  1.  
  2.  
  3.  
  4. pippa v2, di b0z0/iKX
  5.  
  6.  
  7.  
  8. d) cos'e' pippa v2?
  9. r) come non si deduce dal nome, pippa v2 e' un datapipe, ovvero un
  10.    programma che ridireziona tutti i pacchetti tcp diretti ad una porta su
  11.    una macchina ad un altra porta su un altra (o stessa) macchina.
  12.  
  13. d) a che serve?
  14. r) pippa v2 puo' essere usato per mascherare la vera provvenienza di certi
  15.    pacchetti facendoli passare sempre per un altra macchina. questo
  16.    chiaramente puo' essere usato per diversi scopi, dal far passare i
  17.    pacchetti per altre nazioni per complicare il lavoro di chi vorra'
  18.    venire a cercarvi, per mantenere relativamente + segreta la vostra
  19.    identita' su irc o semplicemente per ridirezionare delle porte da
  20.    qualche parte (utilizzabile su gateway per reti interne o cose simili).
  21.  
  22. d) xche' usare pippa v2 e non m$datapipe o altri?
  23. r) perche':
  24.     -) e' scritto in perl, quindi usabile su moltissime piattaforme
  25.        (su tutti gli unix like e anche sui winblows) senza dover
  26.        modificare nulla (a meno di una costante e la path all'interprete).
  27.     -) la destinazione dei pacchetti puo' essere fissa (usando il modo non
  28.        interattivo) o cambiata al volo al momento dell'uso (con il modo 
  29.        interattivo) senza dover far ripartire ogni volta il datapipe.
  30.     -) ha il supporto per i proxy server socks (v4 e v5) modificabili
  31.        anche al volo nel modo interattivo.
  32.     -) due o piu' pippa v2 in modo interattivo e non possono essere
  33.        collegati facilmente in serie (anche poi via un socks
  34.        proxy) rendendo la ricerca della sorgente dei pacchetti +
  35.        complicata.
  36.     -) pippa v2 ha un po' di opzioni di logging delle connesioni.
  37.     -) dovrebbe funzionare e hai il source per aggiungerci quello che
  38.        vuoi senza perdere molto tempo.
  39.  
  40. d) requisiti?
  41. r) il sistema deve avere installato il perl5. per poter usare il supporto
  42.    per server socks si dovra' disporre anche del socks perl module
  43.    (reperibile al http://www.perl.com/CPAN/modules/by-module/Net/). per
  44.    pingare una macchina dal modo interattivo inoltre pippa v2 usera' un
  45.    comando 'ping' che si suppone sia presente sulla macchina.
  46.  
  47. d) come si usa? 
  48. r) beh, per avere una schermata di tutte le possibili opzioni alla command
  49.    line basta lanciare pippa v2 con un '-h 1'. ecco qualche spiegazione
  50.    per ogni comando cmq:
  51.      -p xxxx       : specifica la porta sulla quale pippa v2 aspetta
  52.                      eventuali connessioni.
  53.      -d 1          : saranno visualizzate sull'output tutte le connessioni
  54.                      avvenute.
  55.      -b 1          : pippa v2 si binda (attacca? va be', da bind) su tutti
  56.                      gli indirizzi della macchina (in caso contrario si
  57.                      binda solo su quello ottenuto da `hostname`)
  58.      -F 1          : usa il modo non interattivo. in questo caso pippa v2
  59.                      semplicemente mandera' tutti i pacchetti alla
  60.                      destinazione desiderata scelta dalle opzioni -P e -H
  61.                      ed eventualmente potra' mandare il comando -I.
  62.      -P xxxx       : porta alla quale connettersi (se usato con -F)
  63.      -H xxxx       : host al quale connettersi (se usato con -F)
  64.      -I xxxx       : stringa da mandare all'inizio della connessione (se
  65.                      usato con -F)
  66.      -S 1          : usa il socks proxy specificato dalle opzioni -s, -t,
  67.                      -v, -u e -k.
  68.      -s xxxx       : socks proxy da usare
  69.      -t xxxx       : porta del socks proxy da usare
  70.      -v x          : protocol version del socks proxy (4 o 5)
  71.      -u xxxx       : utente sul proxy socks (di default anonimo)
  72.      -k xxxx       : password sul proxy socks
  73.    se lanciato in modo interattivo il pippa v2 puo' essere comandato
  74.    dall'esterno. connettendovi alla porta del host sulla quale avete
  75.    lanciato pippa vi verra' un prompt "pippa>". con 'help' avrete qualche
  76.    suggerimento. + esattamente i comandi sono:
  77.      open <host> <port>       : connettiti alla porta <port> del <host>
  78.      prox <host> <port>       : setta il socks proxy al sito <host> alla
  79.                                 porta <port>. se usato senza parametri il
  80.                                 comando disabilita l'uso del socks proxy.
  81.      pvar <user> <pass> <ver> : setta l'utente, la password e la versione
  82.                                 del socks proxy. se usato senza parametri
  83.                                 toglie l'uso dell'autentificazione con
  84.                                 user/pass.
  85.      ping <host>              : esegue tre ping al host desiderato.
  86.      stop                     : esegue la chiusura del pippa v2,
  87.                                 principale, lasciando pur sempre attiva 
  88.                                 la connessione attuale.
  89.      exit,quit                : chiude la sessione attuale.
  90.      help                     : un riassunto dei comandi.
  91.  
  92. d) qualche esempio di uso?
  93. r) massi'..
  94.     pippa -p 3456 &
  95.       fa partire pippa v2 in modo interattivo sulla porta 3456
  96.     pippa -p 3456 -b 1 &
  97.       come prima ma pippa v2 si bindera' su tutti gli indirizzi del host
  98.     pippa -p 3456 -b 1 -d 1  2>&1 > pippalog &
  99.       come prima ma le connessioni verranno loggate nel file pippalog
  100.     pippa -F 1 -P 6667 -H irc.ais.net &
  101.       ridireziona tutti i pacchetti in entrata (sulla porta di default
  102.       2345) al sito irc.ais.net alla porta 6667. questo e' un esempio di
  103.       come usare pippa v2 x irc mostrando cosi' solo l'ip dove e' stato
  104.       installato pippa.
  105.     pippa -F 1 -P 23 -H un.wingate.com -I 'open irc.ais.net 6667' &
  106.       qui i pacchetti in entrata verranno ridirezionati al sito
  107.       un.wingate.com alla porta 23. all'inizio di ogni connessione verra'
  108.       mandata la stringa 'open irc.ais.net 6667'. questo e' un tipico modo
  109.       per usare un wingate per andare su irc (in questo caso il pippa v2
  110.       potete eseguirlo sulla vostra macchina locale e settare il server
  111.       per il vostro client irc alla porta 2345 della vostra macchina).
  112.       chiaramente le risposte del wingate non saranno chiare al vostro
  113.       client irc, ma fa nulla, dopo un po' gli passa.
  114.     pippa -F 1 -P 6667 -H irc.ais.net -S 1 -s socks.proxy.com -t 1080
  115.       qui i pacchetti in entrata vengono mandati al sito irc.ais.net alla
  116.       porta 6667 usando il socks proxy socks.proxy.com piazziato sulla
  117.       porta 1080. questo e' un tipico modo per usare un socks proxy per
  118.       andare su irc quando il vostro client non ha il supporto socks gia'
  119.       integrato. anche qui fate girare pippa v2 sul vostro pc e settate il
  120.       server irc del vostro client sulla porta 2345 della vostra macchina. 
  121.    come esempi di cmdline credo bastino, non e' poi cosi' difficile credo.
  122.    per quanto riguarda il modo inteattivo non c'e' molto da fare esempi
  123.    se effetivamente sapete cosa vogliate fare. 
  124.  
  125. d) problemi conosciuti?
  126. r) connettendosi alla porta 23 (telnet) via pippa v2 in modo interattivo
  127.    con alcuni client telnet all'uscita si potrebbe verificare un strano
  128.    comportamento xche' gli ultimi comandi mandati dal demone non saranno
  129.    interpretati. in caso succeda vi basta rimettere il client telnet in
  130.    line mode o chiuderlo e riaprirlo.
  131.  
  132. d) quanto costa?
  133. r) ma nulla, se trovate pippa v2 di qualche utilita' mandatemi una mail a
  134.    b0z0@realitylimited.com o intrattenetemi su irc.
  135.  
  136. d) dediche, saluti o altro?
  137. r) finalmente (forse) non dovro' + ascoltare i problemi impossibili delle
  138.    troppe xsone che vogliono usare un socks proxy ma dicono che bitchx non
  139.    compila e/o che non riescono ad installare/configurare socks5.
  140.    saluti generici a tutti i fratelli e le sorelle, soprattutto quelli/e 
  141.    che mi tirano su di morale di tanto in tanto.
  142.  
  143. d) allora dov'e'?
  144. r) ecco...
  145.  
  146. ---------->8------------------------------------------8<---------------------
  147. #!/usr/bin/perl
  148.  
  149. #
  150. # pippa v2, a network datapipe
  151. # by b0z0/iKX, late 1998
  152. # contacts: b0z0@realitylimited.com
  153. #
  154. # start it with the -h 1 option to get some help
  155. # write help at the pippa> prompt to get some help on the interactive mode
  156. #
  157. # this has been tested.
  158. #
  159.  
  160. $socks_installed=1;        # set this to 0 if ya don't have socks pm
  161.  
  162. use Socket;
  163. require "getopt.pl";
  164. if ($socks_installed) {use Net::SOCKS;}
  165.  
  166. $SIG{'CHLD'}='IGNORE';
  167.  
  168. &Getopt('hpdbPHFISstvuk');        # Get some needed cmdline options
  169. $help=$opt_h;
  170. $port=$opt_p;
  171. $bindany=$opt_b;
  172. $debug=$opt_d;
  173. $destport=$opt_P;
  174. $desthost=$opt_H;
  175. $nonint=$opt_F;
  176. $initstr=$opt_I;
  177. $usesocks=$opt_S;
  178. $sockserver=$opt_s;
  179. $sockport=$opt_t;
  180. $sockversion=$opt_v;
  181. $sockuser=$opt_u;
  182. $sockpass=$opt_k;
  183.  
  184. $port=2345 unless $port;    # some defaults
  185. $destport=25 unless $destport;
  186. $desthost="127.0.0.1" unless $desthost;
  187. $sockport=1080 unless $sockport;
  188. $sockversion=4 unless $sockversion;
  189. $usesocks=0 unless (($usesocks) and ($socks_installed));
  190.  
  191. if ($help) {
  192.  print "pippa usage:\n";
  193.  print "  -h 1           = help\n";
  194.  print "  -p xxxx        = run pippa on port xxxx\n";
  195.  print "  -d 1           = output debug infos\n";
  196.  print "  -b 1           = bind to any adress of the machine\n";
  197.  print "  -F 1           = non interactive mode, just pipe to -H -P\n";
  198.  print "     -P xxxx     = fix destination port to xxxx\n";
  199.  print "     -H xxxx     = fix destination host to xxxx\n";
  200.  print "     -I xxxxx    = send string xxxxx at beginning\n";
  201.  if ($socks_installed){
  202.   print "  -S 1           = use a socks proxy for connections \n";
  203.   print "     -s xxxx     = socks proxy to use\n";
  204.   print "     -t xxxx     = socks proxy port (default 1080)\n";
  205.   print "     -v x        = socks proxy protocol version (default 4)\n";
  206.   print "     -u xxxx     = socks proxy username (default anon login)\n";
  207.   print "     -k xxxx     = socks proxy password (default anon login)\n\n";
  208.  }
  209.  exit();
  210. }
  211.  
  212. $AF_INET=2;
  213.  
  214. # This should very probably change for some operating systems
  215. # Check the socket include files (sys/socket.h) for this value
  216.  
  217. $SOCK_STREAM=1;        # should be 2 for SunOS
  218.  
  219. $sockaddr='S n a4 x8';
  220.  
  221. chop($hostname=`hostname`);    # Infos on machine running pippa
  222. ($name,$aliases,$type,$len,$thisaddr)= gethostbyname($hostname) if $hostname;
  223.  
  224.  
  225. ($name,$aliases,$proto)=getprotobyname('tcp');
  226. if($port !~ /^\d+$/) {
  227.    ($name, $aliases, $port) = getservbyname($port,'tcp');
  228. }
  229.  
  230. $thisaddr=INADDR_ANY if ($bindany or !($thisaddr));  # bind to any address
  231.  
  232. $this= pack($sockaddr,$AF_INET,$port,$thisaddr);
  233. select(NS); $|=1; select(STDOUT); $|=1;
  234.  
  235. socket(S,$AF_INET, $SOCK_STREAM, $proto) || die "socket: $!";
  236. bind(S,$this) || die "bind: $!";
  237. listen(S,5) || die "connect: $!";    # Stay on port and wait for conns
  238.  
  239. select(S); $|=1; select(STDOUT);
  240.  
  241. for ($con=1;;$con++) {
  242.  ($addr=accept(NS,S)) || die $!;
  243.  if (($child=fork())==0) {
  244.    ($af,$port,$inetaddr)=unpack($sockaddr,$addr);
  245.    @inetaddr=unpack('C4',$inetaddr);
  246.  
  247.    @datetime=localtime(time);
  248.    $datetime[4]++;
  249.    print "$datetime[3]/$datetime[4]/$datetime[5] " if $debug; 
  250.    print "$datetime[2]:$datetime[1]:$datetime[0] from " if $debug;
  251.    print "$inetaddr[0].$inetaddr[1].$inetaddr[2].$inetaddr[3]" if $debug;
  252.    print ":$port connection nr=$con\n" if $debug;
  253.         
  254.    print NS "pippa> " if !($nonint);
  255.    select(S); $|=1; select(STDOUT); $|=1;
  256.  
  257.    openconn() if ($nonint);
  258.    exit() if $nonint;
  259.    while (<NS>) {
  260.     print STDOUT "nr=$con command: $_" if ($debug and !($nonint));
  261.     @command=split(' ',$_);
  262.     $_=$command[0];
  263.     CMDLOOP: {
  264.      if (/^open$/) {
  265.            ::openconn();
  266.            last CMDLOOP;
  267.        }
  268.  
  269.      if (/^prox$/) {
  270.            $command[2]=1080 if (!($command[2]));
  271.            $sockserver=$command[1];
  272.            $sockport=$command[2];
  273.            $usesocks=0;
  274.            $usesocks=1 if (($command[1]) and ($socks_installed));
  275.            last CMDLOOP;
  276.      }
  277.  
  278.      if (/^pvar$/) {
  279.            $command[3]=4 if (!($command[3] == 5));
  280.            $sockuser=$command[1];
  281.            $sockpass=$command[2];
  282.            $sockversion=$command[3];
  283.            last CMDLOOP;
  284.      }
  285.  
  286.      if (/^ping$/) {
  287.        if (!($command[1]) or ($command[2])) {
  288.           print NS "bad ping params\n";
  289.        }
  290.        elsif (!($command[1] =~ /^(\w+\.*)+$/)) {
  291.           print NS "nice params\n";
  292.        }
  293.        else {
  294.           open(SAVEOUT,">&STDOUT");
  295.           open(SAVEERR,">&STDERR");
  296.  
  297.           open(STDOUT,">&NS");
  298.           open(STDERR,">&STDOUT");
  299.           system("ping -c 3 $command[1]");
  300.           close(STDOUT);
  301.           close(STDERR);
  302.  
  303.           open(STDOUT,">&SAVEOUT");
  304.           open(STDERR,">&SAVEERR");
  305.        }
  306.        last CMDLOOP;
  307.      }
  308.  
  309.      if (/^help$/) {
  310.        print NS "avaiable commands:\n";
  311.        print NS "  open <host> <port>       : connect to <host> at <port>\n";
  312.        print NS "  prox <host> <port>       : use socks proxy <host>:<port>\n";
  313.        print NS "  pvar <user> <pass> <ver> : proxy auth: user, pass and ver\n";
  314.        print NS "  ping <host>              : ping <host> three times\n";
  315.        print NS "  help                     : this shit\n";
  316.        print NS "  stop                     : stop main pippa\n";
  317.        print NS "  quit, exit               : bail out\n\n";
  318.        last CMDLOOP;
  319.      }
  320.  
  321.      if (/^$/) { last CMDLOOP; }
  322.  
  323.      if (/^stop$/) {
  324.        kill 15, getppid();
  325.        last CMDLOOP;
  326.      }
  327.  
  328.      if ((/^quit$/) or (/^exit$/)) {
  329.        close(NS);
  330.        exit();
  331.      }
  332.      print NS "bad command\n";
  333.     }
  334.    print NS "pippa> " if !($nonint);
  335.    exit() if $nonint;
  336.    }
  337.  close(NS);
  338.  exit();
  339.  }
  340. close(NS);
  341. }
  342.  
  343. sub openconn {
  344.  DOOPEN: {
  345.    $command[1]=$desthost if $nonint;
  346.    $command[2]=$destport if $nonint;
  347.           
  348.    if ((!($command[1])) or (!($command[2])) or $command[3]) {
  349.       print NS "bad params\n";
  350.       last DOOPEN;
  351.    }
  352.    $_=$command[2];
  353.  
  354.    if($_ !~ /^\d+$/) {
  355.      ($name, $aliases, $port) = getservbyname($command[2],'tcp');
  356.      print NS "bad port\n" if !($port);
  357.      last DOOPEN if !($port);
  358.      $command[2]=$port;
  359.    }
  360.    elsif ($command[2] > 65535) {
  361.       print NS "port > 65535? cool\n";
  362.       last DOOPEN;
  363.    }
  364.    ::doopen() if (!($usesocks));
  365.    ::doopensocks() if ($usesocks);
  366.  }
  367. }
  368.  
  369.  
  370. sub doopen {
  371.    $outta= pack($sockaddr,$AF_INET,0,$thisaddr);
  372.    socket(OUT,$AF_INET, $SOCK_STREAM, $proto) || die "socket: $!";
  373.    bind(OUT,$outta) || die "bind: $!";
  374.  
  375.    ($name,$aliases,$type,$len,$targetaddr)=gethostbyname($command[1]);
  376.       
  377.    $that=pack($sockaddr, $AF_INET, $command[2],$targetaddr);
  378.  
  379.    print NS "ok, connecting... \n" if !($nonint);
  380.    if (connect(OUT,$that)) {
  381.       print NS "ok, connected!\n" if !($nonint);
  382.       select(OUT); $|=1; select(STDOUT);
  383.       print OUT "$initstr\n" if ($nonint and $initstr);
  384.       if ($child_c=fork()){
  385.          while (read(OUT,$buf,1)) { print NS $buf;}         
  386.          sleep 3;
  387.          kill 9,$child_c if $child_c;
  388.       }
  389.       else { 
  390.          while (read(NS,$buffo,1)) { print OUT $buffo;}
  391.       }
  392.    }
  393.    else { print NS "error: $!\n"; }
  394. }
  395.  
  396. sub doopensocks {
  397.    $forzo=0;
  398.    $forzo=1 if ($sockuser and $sockpass);
  399.    my $sock = new Net::SOCKS(socks_addr => $sockserver,
  400.                 socks_port => $sockport,
  401.                 user_id => $sockuser,
  402.                 user_password => $sockpass,
  403.                 force_nonanonymous => $forzo,
  404.                 protocol_version => $sockversion);
  405.  
  406.    my $f= $sock->connect(peer_addr => $command[1], peer_port => $command[2]);
  407.  
  408.    $s_num=$sock->param('status_num');
  409.    if ($s_num == SOCKS_OKAY) {
  410.       if ($child_c=fork()){
  411.          while (read($f,$buf,1)) { print NS $buf;}
  412.          sleep 3;
  413.          $sock->close();
  414.          kill 9,$child_c if $child_c;
  415.       }
  416.       else {
  417.          while (read(NS,$buffo,1)) { print $f $buffo;}
  418.       }
  419.    }
  420.    else {
  421.      $s_err=Net::SOCKS::status_message($s_num);
  422.      print NS "Socks error: $s_err\n";
  423.    }
  424. }
  425.